﻿using System.Collections.Generic;
using System.Collections;
using UnityEngine;
using ProtoBuf.Message;
using System;

public class HeroExtPackage
{
    public int packageId;
    public string packageName;
    public string packageIcon;
    public string packageBg;
    public ItemBase coinItemBase;
    public bool isGetted = false;
    
    public List<PackageHero> heros = new List<PackageHero>();

    public HeroExtPackage(Table.DataModel.TableAutoChessExtraHeroPack data)
    {
        packageId = data.packetId;
        packageName = data.packageName;
        packageIcon = data.packageIcon;
        packageBg = data.packagebg;
        ParseHeros(data.heroIds);
        coinItemBase = new ItemBase() { type = (int)ItemBaseType.COIN3, num = 0 };
    }

    public string GetHeroFrameName(int heroId)
    {
        var chessHeroTable = Table.Blo.AutoChessBlo.GetChessHero(heroId);
        return CommonMethod.GetChessHeroFrame(chessHeroTable.rare);
    }

    private void ParseHeros(string strHero)
    {
        var heroArr = strHero.Split(',');
        for (int i = 0; i < heroArr.Length; i++)
        {
            int heroId = int.Parse(heroArr[i]);
            heros.Add(new PackageHero(heroId,GetHeroFrameName(heroId)));
        }
    }

    public void RefreshServerData(AutochessExtraPackInfo serverData, List<int> gettedHeros)
    {
        coinItemBase = serverData.cost;
        isGetted = serverData.isActived;
        for (int i = 0; i < gettedHeros.Count; i++)
        {
            var tempHerp = heros.Find((a) => { return a.heroId == gettedHeros[i]; });
            if (tempHerp != null)
            {
                tempHerp.isGetted = true;
            }
        }
    }
}

public class PackageHero
{
    public int heroId;
    public bool isGetted = false;
    public ItemBase itemBase;
    public string frameName;
    public PackageHero(int heroId,string frameName)
    {
        this.heroId = heroId;
        this.frameName = frameName;
        itemBase = new ItemBase() {id = heroId,num = 1,type =(int)ItemBaseType.HERO };
    }
}
